package com.mrzhou.swagger.config;

import com.mrzhou.core.tool.yml.YamlPropertySourceFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@PropertySource(name="cloud-swagger-start", value = {"classpath:cloud-swagger2.yml"}, factory = YamlPropertySourceFactory.class)
@EnableConfigurationProperties({Swagger2Properties.class})
public class Swagger2WebConfiguration  implements WebMvcConfigurer {

    /**
     * 将以下路径添加到SpringMVC中
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(new String[]{"/js/**"}).addResourceLocations(new String[]{"classpath:/js/"});
        registry.addResourceHandler(new String[]{"doc.html"}).addResourceLocations(new String[]{"classpath:/META-INF/resources/"});
        registry.addResourceHandler(new String[]{"/webjars/**"}).addResourceLocations(new String[]{"classpath:/META-INF/resources/webjars/"});
    }

}
